<!DOCTYPE html>
<html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="shmged.com.shlcm.utils.*"%>
<%@ page import="wt.inf.container.WTContainer"%>
<%@ page import="wt.inf.container.WTContainerRef"%>
<%@ page import="wt.folder.Folder" %>
<%@ page import="wt.folder.FolderHelper" %>
<%@page import="wt.httpgw.URLFactory"%>
<head>
</head>
<%
String baseUrl = new URLFactory().getBaseHREF();
String contName = CmSettings.getSection("DefaultLocation").get("ShmgedContainer");
String tree =CmCreateDocHelper.getAllFolder(contName);

%>


<body>
<center>
	<div style="margin:10px 0;"></div>
	<jsp:include page="createFolder.jsp"></jsp:include>
	<jsp:include page="browseCreateDoc.jsp"></jsp:include>
	<div class="easyui-layout" style="width:720px;height:750px;" id="treeFolders" name="treeFolders">
		<div data-options="region:'west',split:true" title="文件夹" style="width:130px;" >
		<div style="margin:10px 0;"></div>
		<input class="easyui-searchbox" data-options="prompt:'Please Input Value',searcher:doSearch" style="width:130px;"></input>
		<div style="margin:10px 0;"></div>
		<ul id="folderTree"></ul>
	</div>
		<div data-options="region:'center',title:'文件夹内容',iconCls:''"> 
			<div style="padding:5px;">
			<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="javaScript:createDoc()">创建文档</a>
			<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove'" onclick="javaScript:deleteSelections('#tt','浏览文档')">删除</a>
			<a href="#" class="easyui-linkbutton" onclick="javaScript:browseAddUpdateTab('','')">修改</a>
			<a href="#" class="easyui-linkbutton" onclick="javaScript:createFolder()">创建文件夹</a>
			<a href="#" class="easyui-linkbutton" onclick="javaScript:downloadFiles('#tt')">下载文件</a>
			</div>
	      <table id="tt"></table>
		</div>
	
	</div>
</center>
<script>
		//初始化树
		initFolderTree();
		//初始化table
		initDocTable("/Default");
		function initFolderTree(){
			$('#folderTree').tree({ 
				animate:true,
			    dnd:true,
			    data:<%=tree%>,
					onClick:function(node){	
			    	var path=getFullPath(node);
					initDocTable(path);
					}
			});
			//初始化的时候tree默认选择更节点/Default
			var node = $('#folderTree').tree('find',"/Defualt");
			$('#folderTree').tree('expandTo', node.target).tree('select', node.target); 
		}
		
		function initDocTable(folderName){
			var url='<%=baseUrl%>shmged/jsp/com/shlcm/documents/jspSearchDocument.jsp';
			  $('#tt').datagrid({   
			      url:url,
			      queryParams:{folderName:folderName},
			      nowrap:false,
			      loadMsg:'正在加载数据，请稍等。。。',
				  fitColumns: true,
			      columns:[[   
					  {field:'id',title:'id',width:100,checkbox:true},  
					  {field:'type',title:'类型',width:15}, 
			          {field:'name',title:'名称',width:50,
			        	  //添加超级链 
	                     formatter:function(value,rowData,rowIndex){
							if(rowData.number!=""){
	                    		 return "<a href='javaScript:void(0)' onclick=\"javaScript:addTab('','','"+rowData.id+"','"+rowData.name+"')\">"+rowData.name+"</a>";  
							}else{
								  return "<a href='javaScript:void(0)' onclick=\"javaScript:expandTo('"+rowData.name+"')\">"+rowData.name+"</a>";
								}

			          }

				          },
			          {field:'state',title:'状态',width:40}, 
			          {field:'version',title:'版本',width:40},
			          {field:'modifyUser',title:'更新者',width:60},
			          {field:'time',title:'更新时间',width:100}    
			      ]] 
			    }); 
		}

		//查询tree的某一个节点
		function doSearch(value){
			expandTo(value);
		}
		//展开某一个节点的时候 打开这个节点的table
		function expandTo(value){
			var node = $('#folderTree').tree('find',value);
			$('#folderTree').tree('expandTo', node.target).tree('select', node.target);
			//var path=getFullPath(node);
			//initDocTable(path);
		}

		//得到完整路劲
		function getFullPath(node)
		{
			var s = node.text;
			var path="/"+s;
			var pnode = $('#folderTree').tree('getParent',node.target);
			while(pnode!=null)
			{
				path="/"+pnode.text+path;
				node=pnode;
				pnode = $('#folderTree').tree('getParent',node.target);
			}
			return path;
			
		}

		//刷新当前tab
		function refe(){
			$("#cmTabs").tabs('select',"浏览文档");  
	        var tab = $('#cmTabs').tabs('getSelected');       
	        $("#cmTabs").tabs('update',{  
	        tab:tab,  
	        options:{  
	           title:'浏览文档',  
	           style:{padding:'1px'},  
	       //href:URL, // 使用href会导致页面加载两次，所以使用content代替   
	           content:'<iframe name="indextab" scrolling="auto" frameborder="0" style="width:100%;height:100%;"></iframe>',  
	       closable:false,  
	       fit:true,  
	       selected:true,  
	       closable:true
	        }  
	         });  
		}




	
		//创建一个新的tab 文档信息
		function browseAddUpdateTab(tabObj,tabId){
			var rows = $('#tt').datagrid('getSelections');
			if(rows.length>1)
			{
				$.messager.alert('提示', "只能选择一项修改");
			}else if(rows.length==0)
			{
				$.messager.alert('提示', "请选择要修改的文档");
			}else if(rows[0].state=="")
			{
				$.messager.alert('提示', "请选择文档");
			}else{
				var oid=rows[0].id;
				var defaultTabId = "cmTabs";
				if(tabId){
					defaultTabId = tabId;
				}
				var tabDefault = {
					href:pageBaseUrl+"shmged/jsp/com/shlcm/documents/updateDoc.jsp?oid="+oid+"&type=browse",
					title:"修改文档",
					selected: true,
					closable:true
				};
				var options ;
				if(tabObj){
				    var empty = {};
					options = $.extend(empty,tabDefault,tabObj);
				}else{
					options = tabDefault;
				}
				if($('#'+defaultTabId).tabs("exists",options.title)){
					$('#'+defaultTabId).tabs('select',options.title);
				}else{
				    $('#'+defaultTabId).tabs('add',options);
				}
		//		alert(tab.outerHeight()+":"+tab.innerHeight());
		//	    alert("index:"+index);
				//var oldHeight = p.panel('panel').outerHeight();  
				//setHeight();
			}
		}

		

		 var cmBaseUrl = '<%=baseUrl%>';
	</script>
</body>
</html>